package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.service.WeChatService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IcEventProcess;
import com.ruoyi.system.service.IIcEventProcessService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事件管理流程Controller
 * 
 * @author ruoyi
 * @date 2024-07-06
 */
@Controller
@RequestMapping("/system/ic_event_process")
public class IcEventProcessController extends BaseController
{
    private String prefix = "system/ic_event_process";

    @Autowired
    private IIcEventProcessService icEventProcessService;

    @Autowired
    private WeChatService weChatService;

    @RequiresPermissions("system:ic_event_process:view")
    @GetMapping()
    public String ic_event_process()
    {
        return prefix + "/ic_event_process";
    }

    /**
     * 查询事件管理流程列表
     */
    @RequiresPermissions("system:ic_event_process:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IcEventProcess icEventProcess)
    {
        startPage();
        List<IcEventProcess> list = icEventProcessService.selectIcEventProcessList(icEventProcess);
        return getDataTable(list);
    }

    /**
     * 导出事件管理流程列表
     */
    @RequiresPermissions("system:ic_event_process:export")
    @Log(title = "事件管理流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IcEventProcess icEventProcess)
    {
        List<IcEventProcess> list = icEventProcessService.selectIcEventProcessList(icEventProcess);
        ExcelUtil<IcEventProcess> util = new ExcelUtil<IcEventProcess>(IcEventProcess.class);
        return util.exportExcel(list, "事件管理流程数据");
    }

    @GetMapping("/event/{eventId}")
    @ResponseBody
    public AjaxResult getEventDetail(@PathVariable Long eventId) {
        AjaxResult result = weChatService.getEventDetailById(eventId);
        return result;
    }

    /**
     * 通过流程
     */
    @PostMapping("/event/pass")
    @ResponseBody
    public AjaxResult passEventProcess(IcEventProcess process) {
        AjaxResult result = icEventProcessService.passEventProcess(process);
        return result;
    }

    /**
     * 新增事件管理流程
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存事件管理流程
     */
    @RequiresPermissions("system:ic_event_process:add")
    @Log(title = "事件管理流程", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IcEventProcess icEventProcess)
    {
        return toAjax(icEventProcessService.insertIcEventProcess(icEventProcess));
    }

    /**
     * 修改事件管理流程
     */
    @RequiresPermissions("system:ic_event_process:edit")
    @GetMapping("/edit/{epId}")
    public String edit(@PathVariable("epId") Long epId, ModelMap mmap)
    {
        IcEventProcess icEventProcess = icEventProcessService.selectIcEventProcessByEpId(epId);
        mmap.put("icEventProcess", icEventProcess);
        return prefix + "/edit";
    }

    /**
     * 修改保存事件管理流程
     */
    @RequiresPermissions("system:ic_event_process:edit")
    @Log(title = "事件管理流程", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IcEventProcess icEventProcess)
    {
        return toAjax(icEventProcessService.updateIcEventProcess(icEventProcess));
    }

    /**
     * 删除事件管理流程
     */
    @RequiresPermissions("system:ic_event_process:remove")
    @Log(title = "事件管理流程", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(icEventProcessService.deleteIcEventProcessByEpIds(ids));
    }
}
